<%@ page contentType="text/html; charset=utf-8" language="java" extends="org.zizi.service.JspPageServlet" %>
<%@page import="java.util.Date"%>
<%@page import="org.zizi.util.DateUtil"%>
<%@page import="org.zizi.util.PagedList"%>
<%@page import="org.zizi.modal.User"%>
<%@page import="org.zizi.manager.Managers"%>
<%@page import="org.zizi.manager.impl.DaoManager"%>
<%@page import="org.zizi.dao.UserDao"%>
<%@page import="org.zizi.util.Pagging"%>
<%@page import="org.zizi.util.RequestParamReplace"%>
<%@page import="org.zizi.manager.LoginManager"%>
<%@page import="org.zizi.dao.InlandRevenueOrgDao"%>
<%@page import="org.zizi.action.UpdateUser"%>
<%@page import="org.zizi.modal.InlandRevenueOrg"%>

<%
	User u = null;
	if (session != null) u = Managers.get(LoginManager.class).getUser(session.getId());
	if (u == null) response.sendRedirect("/login.jsp");

	String name = request.getParameter("name");

	String szPage = request.getParameter("page");
	int p = szPage == null ? 1 : Integer.parseInt(szPage);
	
	Pagging pagging = new Pagging(p);
	
	PagedList<User> list = null;
	if (name != null && !name.isEmpty() && u != null)
	{
		UserDao dao = Managers.get(DaoManager.class).getDao(UserDao.class);
		InlandRevenueOrgDao orgDao = Managers.get(DaoManager.class).getDao(InlandRevenueOrgDao.class);
		
		InlandRevenueOrg org = orgDao.getInlandRevenueOrg(u.getOrgCode());
		
		list = dao.searchManagingUser(name, org.getRelationCode(), pagging.getOffset(), pagging.getLimit());
		if (list != null) pagging.setTotal(list.getTotal());
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>专用设置和技术维护费抵减系统</title>
<jsp:include page="engine.jsp" ></jsp:include>
<script type="text/javascript">

function update(type, id)
{
	var action = new Action("UpdateUser");
	action.type = type;
	action.id = id;
	var callback = function(result)
	{
		location.reload();
	}
	Rpc.call(action, callback);
}

function jump(url)
{
	location.href = url;
}

function logout()
{
	var action = new Action("Logout");
	var callback = function(result)
	{
		location.href = "/login.jsp";
	}
	Rpc.call(action, callback);
}

</script>
<link href="css/common.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.content .user_table {border-collapse:collapse; width:910px; font-size:12px;}
.content .user_table td {border:solid 1px #CCC;}
.content .user_table td a {text-decoration:none; color:#000;}
.content .user_table td a:hover {color:#F00;}
.content .user_table th {border:solid 1px #CCC;}
.content .user_table .query_bar_table {margin:5px 0;}
.content .user_table .query_bar_table td {border:0;}
.pagging {display:inline; margin-right:55px; font-size:12px; float:right; margin-top:10px;}
.pagging a {color:#333; width:20px; height:20px; border:1px solid #CCC; margin:3px; float:left; text-align:center; line-height:20px; text-decoration:none; background-color:#FFF;}
.pagging a:hover {color:#F00; background-color:#CCC;}
.pagging a.current {color:#F00; background-color:#CCC;}
.nop {font-size:14px; font-weight:bold; padding-top:40px;}
.nop a {text-decoration:none; color:#00F;}
</style>
</head>
<body onload="resize()">
	<div id="container">
		<div class="top"></div>
		<div class="nav">
			<div class="navbuttons">
				<div class="navitem" style="background:url(images/main/submit_n.gif)" onclick="jump('/submit.jsp')"></div>
				<div class="navitem" style="background:url(images/main/history_n.gif)" onclick="jump('/history.jsp')"></div>
				<div class="navitem" style="background:url(images/main/types_n.gif)" onclick="jump('/types.jsp')"></div>
				<div class="navitem" style="background:url(images/main/empower_a.gif)" onclick="jump('/empower.jsp')"></div>
			</div>
			<div class="navcmds">
				<div style="background:url(images/main/logout.gif) no-repeat;"><a href="#" onclick="logout(); return false;">退出系统</a></div>
			</div>
		</div>
		<div class="content">
			<%
				if (u != null && u.isEmpowerUser()) {
			%>
			<table class="user_table" cellpadding="0" cellspacing="0" border="0" align="center">
				<tr>
					<td colspan="5" style="border:0;">
						<form method="get">
						<table class="query_bar_table" cellpadding="0" cellspacing="5" border="0" align="left">
							<tr>
								<td>姓名或登陆账号：</td>
								<td><input type="text" name="name" value="<%=name == null ? "" : name %>" /></td>
								<td><input type="submit" value="查询" /></td>
							</tr>
						</table>
						</form>
					</td>
				</tr>
				<tr>
					<td rowspan="2">姓名</td>
					<td rowspan="2">登陆账号</td>
					<td colspan="3">权限设置（点击更改）</td>
				</tr>
				<tr>
					<td>项目类型维护</td>
					<td>抵减清单维护</td>
					<td>设置他人权限</td>
				</tr>
				<%
					if (list != null)
					{
						for (User x : list)
						{
							out.println("<tr>");
							out.println("<td>" + x.getName() + "</td>");
							out.println("<td>" + x.getLogin() + "</td>");
							out.println("<td><a href=\"#\" onclick=\"update('" + UpdateUser.MAINTAIN_TYPE + "'," + x.getId() + ")\">" + (x.isMaintainType() ? "[是]" : "[-]") + "</a></td>");
							out.println("<td><a href=\"#\" onclick=\"update('" + UpdateUser.MAINTAIN_CREDIT + "'," + x.getId() + ")\">" + (x.isMaintainCredit() ? "[是]" : "[-]") + "</a></td>");
							out.println("<td><a href=\"#\" onclick=\"update('" + UpdateUser.EMPOWER_USER + "'," + x.getId() + ")\">" + (x.isEmpowerUser() ? "[是]" : "[-]") + "</a></td>");
							out.println("</tr>");
						}
					}
				%>
			</table>
			<div class="pagging">
				<%
					String query = request.getQueryString();
					query = RequestParamReplace.replace(query, "page", "@PAGE");
					
					String url = request.getRequestURL().toString();
					url += query;
					
					String source = "<a href=\"" + url + "\">@TEXT</a>";
					String current = "<a href=\"" + url + "\" class=\"current\">@TEXT</a>";
					
					pagging.draw(10, out, source, current);
				%>
			</div>
			<% } else { %>
			<div class="nop">对不起，您没有权限维护人员权限。<br/>若权限已更改，请<a href="#" onclick="logout(); return false;">重新登陆！</a></div>
			<% } %>
		</div>
	</div>
</body>
</html>